package com.example.zdxk;

import com.example.zdxk.netty.TcpServer;
import io.netty.channel.ChannelFuture;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import com.ruoyi.common.security.annotation.EnableCustomConfig;
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.net.InetSocketAddress;

/**
 * 	中大信科手腕
 */
@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringCloudApplication
@MapperScan("com.example.zdxk.mapper")//将项目中对应的mapper类的路径加进来就可以了，对应不需要xml文件的时候
public class ZdxkApplication implements CommandLineRunner {

    /**  27服务器
     * 25260：前海
     * 25269：喜讯
     * 35260：指纹仪
     * 35269：api-0.0.1.jsr
     */

    int port = 35260;

//    int port = 25269;
    @Autowired
    private TcpServer tcpServer;

    //@Bean
    //public TcpServer tcpServer() {
//        return new TcpServer();
//    }

    public static void main(String[] args) {
        SpringApplication.run(ZdxkApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

        System.out.println("TCPSERVER启动...");


        //System.out.println(BaiduAPI.getLocName("28.1696094","11292.58732"));
        //System.out.println(GPSUtil.parseLat("2719.24112",""));				//27.320686
        // System.out.println(GPSUtil.parseLng("11324.40608",""));				//113.406768
        //System.out.println(BaiduAPI.getLocName("27.320686","113.406768"));

        InetSocketAddress address = new InetSocketAddress( port );
        ChannelFuture future = tcpServer.start(address);
        Runtime.getRuntime().addShutdownHook(new Thread(){
            @Override
            public void run() {
                tcpServer.destroy();
            }
        });
        future.channel().closeFuture().syncUninterruptibly();


    }

}
